<%@ page language="java" contentType="text/html;charset=UTF-8"
   	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
	function deleteCategory(cat_id){
		if(confirm("Are you sure you want to delete this category?")){
			window.location="delete_category.html?cat_id="+cat_id;
		}	
	}
	
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}
	function Validate()
	  {
		 
		 var cat_name=document.getElementById("txtname").value;
		 if(trim(cat_name)==""){
			 alert("Please enter category name");
			 document.getElementById("txtname").focus();
			 return false;
		 }
		 return true;
	 }	
</script>
</head>
<body>
<center>

<h2>ប្រភេទឯកសារ</h2>
	<table border="0" cellpadding="0" cellspacing="0" width="95%" class="ContentText">
	<form method="post" action="add_category.html" onsubmit="return Validate();">
		<tr align="left">
			<td width="8%" height="25" colspan="3">បញ្ចូលប្រភេទឯកសារ :​ <input type="text" id="txtname" name="txtname" maxlength="500" style="width: 300px;"/>&nbsp;&nbsp;<input type="submit" class="input_button" value="រក្សាទុក"></td>	
		</tr>
	</form>	
		<tr><td colspan="3" height="10"> </td></tr>
		<tr class="myuploadheader" align="center">
			<td width="8%" height="25">លេខ</td>	
			<td width="35%">ប្រភេទឯកសារ</td>	
			<td width="22%">សកម្មភាព</td>
		</tr>
		<%
			String bgcolor="#EEE";
		%>
		<c:if test="${fn:length(data)>0}">
			<c:forEach var="x" begin="0" end="${fn:length(data)-1}" step="1" varStatus ="status">
				<%
					bgcolor=(bgcolor=="#EEE")?"#FFF":"#EEE";
				%>
						<tr bgcolor="<%=bgcolor%>" align="center">
							<td align="center" height="40" style="border-left:solid 1px #DDD; border-bottom:solid 1px #DDD;"><c:out value="${x+1}"/></td>
							<td align="left" style="border-left:solid 1px #DDD; border-bottom:solid 1px #DDD;padding-right: 4px; padding-left: 4px;">
								<a href="edit_category.html?cat_id=${data[x].CATEGORY_ID}">
									<c:out value="${data[x].CATEGORY_NAME}"/>
								</a>
							</td>
							<td style="border:solid 1px #DDD; border-top:solid 0px #DDD;"><a href="edit_category.html?cat_id=${data[x].CATEGORY_ID}">កែប្រែ</a><label style="color:#BBB;">|</label><label style="cursor: pointer; color:#0066FF;" onclick="deleteCategory(${data[x].CATEGORY_ID})">លុបចោល</label></td>
						</tr>
			</c:forEach>
		</c:if>
	</table>

</center>

</body>
</html>